<?php
session_cache_expire(999999999);
if (!isset($_SESSION)) {
    session_start();
}

if (isset($_SESSION['listreference1'])) {
    unset($_SESSION['listreference1']);
    unset($_SESSION['namereference1']);
    unset($_SESSION['slreference1']);
}
$status = $_REQUEST['status'];
if ($status == 0) {
    $l_ngaygiaodich = $l_ngaygiaodich0;
    $l_ngayphathanh = $l_ngayphathanh0;
    $l_thoigiangiaodich = $l_thoigiangiaodich0;
    $l_thoigianphathanh = $l_thoigianphathanh0;
    $type = $l_phathanh;
    $thoigiangiaodich2 = $thoigiangiaodich0;
}
if ($status == 1) {
    $l_ngaygiaodich = $l_ngaygiaodich1;
    $l_ngayphathanh = $l_ngayphathanh1;
    $l_thoigiangiaodich = $l_thoigiangiaodich1;
    $l_thoigianphathanh = $l_thoigianphathanh1;
    $type = $l_giaodich;
    $thoigiangiaodich2 = $thoigiangiaodich1;
}
$thoigianphgd = $l_thoigianphathanh;
$mangquy = array(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4);
$mq = array(1 => array(1, 3), 2 => array(4, 6), 3 => array(7, 9), 4 => array(10, 12));
if (!isset($_REQUEST["abc"])) {
    $_REQUEST["abc"] = "all";
    $typedate = "ngayph";
}
$_SESSION['loaitimkiem'] = $_REQUEST["abc"];
if ($_SESSION['loaitimkiem'] == "ngay") {
    $_REQUEST['datefrom'] = date("Y-m-d");
    $_REQUEST['dateto'] = date("Y-m-d");
    $_REQUEST['vttime'] = $_REQUEST['datefrom'] . " ~ " . $_REQUEST['dateto'];
} else if ($_SESSION['loaitimkiem'] == "thang") {
    $_REQUEST['syear'] = $vyear = date("Y");
    $_REQUEST['smonths'] = date("m");
    $ntt = date("t", mktime(0, 0, 0, $_REQUEST['smonths'], 1, $_REQUEST['syear']));
    if ($_REQUEST['smonths'] < 10) {
        $_REQUEST['vttime'] = $_REQUEST['syear'] . "-0" . $_REQUEST['smonths'] . "-01" . " ~ " . $_REQUEST['syear'] . "-0" . $_REQUEST['smonths'] . "-" . $ntt;
    } else {
        $_REQUEST['vttime'] = $_REQUEST['syear'] . "-" . $_REQUEST['smonths'] . "-01" . " ~ " . $_REQUEST['syear'] . "-" . $_REQUEST['smonths'] . "-" . $ntt;
    }
} else if ($_SESSION['loaitimkiem'] == "qui") {
    $_REQUEST['nam'] = $vyear = date("Y");
    $_REQUEST['qmonths'] = $mangquy[date("m") - 1];
    $ntt = date("t", mktime(0, 0, 0, $mq[$_REQUEST['qmonths']][1], 1, $_REQUEST['nam']));
    if ($mq[$_REQUEST['qmonths']][0] < 10) {
        $_REQUEST['vttime'] = $_REQUEST['nam'] . "-0" . $mq[$_REQUEST['qmonths']][0] . "-01" . " ~ " . $_REQUEST['nam'] . "-0" . $mq[$_REQUEST['qmonths']][1] . "-" . $ntt;
    } else {
        $_REQUEST['vttime'] = $_REQUEST['nam'] . "-" . $mq[$_REQUEST['qmonths']][0] . "-01" . " ~ " . $_REQUEST['nam'] . "-" . $mq[$_REQUEST['qmonths']][1] . "-" . $ntt;
    }
} else if ($_SESSION['loaitimkiem'] == "all") {
    $_REQUEST['nam'] = $vyear = date("Y");
    if (isset($_REQUEST['nam']))
        $_REQUEST['vttime'] = $_REQUEST['nam'] . "-01-01" . " ~ " . $_REQUEST['nam'] . "-12-31";
    else
        $_REQUEST['vttime'] = '~';
}
$_REQUEST['cbcus'] = "";
$arr = array();
$_SESSION['manginvoicetax'] = array();
?>
<style>
    <!--
    * {padding:0; margin:0;}
    -->
</style>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<style type="text/css">
    #content_menu_expand{
        position:absolute; 
        right:-5px;
        top:20px;
        z-index:999;
        background-color: #ffffff;
        -moz-border-radius: 7px;
        -webkit-border-radius: 7px;
        color: #000000;
        width:300px; 
        max-height:180px;
        overflow:auto;
    }
    .passul{padding-left:0; border:1px solid black}
    .bgkhac {background: #eee;}
    .passul ul{padding:0px}
    .passul ul li {color:#474747; font-size:12px;padding: 5px 0;padding-left:5px;list-style: none;}
    .passul ul li:hover { background: #0A246A;color:white;text-decoration: none;list-style: none;}
</style>
<script type="text/javascript">
    function delorder(loaitimkiem,status,typedate,not,count){
        if(count>0){
            var hoi= confirm("<?php echo $l_areyousure; ?>");
            if (hoi==true) {
                var str="";
                for(var i=0;i<count;i++){
                    if(document.getElementById('check'+i).checked==true)
                        str+='_'+document.getElementById('check'+i).value;
                }
                if(str!=""){
                    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
                        xmlhttp=new XMLHttpRequest();
                    }else{// code for IE6, IE5
                        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    xmlhttp.onreadystatechange=function(){
                        if (xmlhttp.readyState==4 && xmlhttp.status==200){
                            document.getElementById("listEmp").innerHTML=xmlhttp.responseText;
                        }
                    }
                    xmlhttp.open("GET","ajax/acc/delInvoices.php?loaitimkiem="+loaitimkiem+"&status="+status+"&typedate="+typedate+"&not="+not+"&str="+str,true);
                    xmlhttp.send();
                }else
                    alert("No check");
            }
        }else
            alert('No data');
    }
    function showUser1(str){
        if (str==""){
            document.getElementById("txtHint").innerHTML="";
            return;
        } 
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","ajax/getuser1.php?q="+str,true);
        xmlhttp.send();
    }
    function showReference1(str){ 
        if (str==""){
            document.getElementById("txtHint1").innerHTML="";
            return;
        } 
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("txtHint1").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","ajax/getreference1.php?idemployee="+str,true);
        xmlhttp.send();
    }
    function rmReference1(str){ 
        if (str==""){
            document.getElementById("txtHint1").innerHTML="";
            return;
        } 
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("txtHint1").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","ajax/rmreference1.php?idemployee="+str,true);
        xmlhttp.send();
    }
    $(document).ready(function(){
        $("#inputString").autocomplete("operations/rpc_search_invoice_tax.php", {
            selectFirst: true
        });
        $('#content_menu_expand').hide();
        $(document).click(function() {
            $("#content_menu_expand").hide();
        });
        $('#content_menu_expand').click(function(e) {
            e.stopPropagation();
        });

        $('#menu_expand').click(function() {
            if ($('#content_menu_expand').is(":hidden")) {
                var gt=document.getElementById("checkkhung").checked;
                if(gt==false){
                    $('#content_menu_expand').show();
                }
            }
            else {
                $('#content_menu_expand').hide();
            }
            return false;
        });
        $('#close_menu').click(function() {
            $('#content_menu_expand').hide();
            return false;
        });

        $("ul.menu_inside li a").hover(function() {
            $(this).parent().find("ul.subnav").slideDown(0).show();
            $(this).parent().hover(function() {
            }, function(){
                $(this).parent().find("ul.subnav").slideUp(0);
            });
        }).hover(function() {
            $(this).addClass("subhover");
        }, function(){
            $(this).removeClass("subhover");
        });
    });

    function Load(){
        $("#inputString").autocomplete("operations/rpc_search_invoice_tax.php", {
            selectFirst: true
        });
        $('#content_menu_expand').hide();
        $(document).click(function() {
            $("#content_menu_expand").hide();
        });
        $('#content_menu_expand').click(function(e) {
            e.stopPropagation();
        });

        $('#menu_expand').click(function() {
            if ($('#content_menu_expand').is(":hidden")) {
                var gt=document.getElementById("checkkhung").checked;
                if(gt==false){
                    $('#content_menu_expand').show();
                }
            }
            else {
                $('#content_menu_expand').hide();
            }
            return false;
        });
        $('#close_menu').click(function() {
            $('#content_menu_expand').hide();
            return false;
        });

        $("ul.menu_inside li a").hover(function() {
            $(this).parent().find("ul.subnav").slideDown(0).show();
            $(this).parent().hover(function() {
            }, function(){
                $(this).parent().find("ul.subnav").slideUp(0);
            });
        }).hover(function() {
            $(this).addClass("subhover");
        }, function(){
            $(this).removeClass("subhover");
        });
        new JsDatePick({
            useMode:2,
            target:"datefrom",
            dateFormat:"%Y-%m-%d"
        });
        new JsDatePick({
            useMode:2,
            target:"dateto",
            dateFormat:"%Y-%m-%d"
        });
		
    }
	

    /*function xlsearch()
{
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
                                                                                  if (xmlhttp.readyState==4 && xmlhttp.status==200){
                                                                                        document.getElementById("viewsearch").innerHTML=xmlhttp.responseText;
                                                                                  }
                                                                          }
        sfromdate=document.getElementById("datefrom").value;
        stodate=document.getElementById("dateto").value;
        var setax = document.getElementById("cbcus");
        var scbcus = setax.options[setax.selectedIndex].value;
        xmlhttp.open("GET","ajax/acc/searchpurchase.php?search=Search&datefrom="+sfromdate+"&dateto="+stodate+"&cbcus="+scbcus,true);
        xmlhttp.send();
}*/
    /*function sort(page,str,co,s)
{
        sfromdate=document.getElementById("datefrom").value;
        stodate=document.getElementById("dateto").value;
        //var setax = document.getElementById("cbcus");
        //var scbcus = setax.options[setax.selectedIndex].value;
        var scbcus = document.getElementById("inputString").value;
        //alert(sfromdate+" --- "+stodate+" --- "+scbcus+" -- "+s);
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
                                                                                  if (xmlhttp.readyState==4 && xmlhttp.status==200){
                                                                                        document.getElementById("viewsearch").innerHTML=xmlhttp.responseText;
                                                                                        resetvalue();
                                                                                  }
                                                                          }
        xmlhttp.open("GET","ajax/acc/sortsearchpurchase.php?datefrom="+sfromdate+"&dateto="+stodate+"&cbcus="+encodeURIComponent(scbcus)+"&page="+page+"&str="+str+"&co="+co+"&search="+s,true);
        xmlhttp.send();
}*/

    function clickCustomer(gt){
        document.getElementById("inputString").value=gt;
        $('#content_menu_expand').hide();
    }

    function viewclick(status){
        //var txtloaitimkiem =$('input[name=abc]:checked').val();
        //alert(txtloaitimkiem);
        var checkshow="";
        if(document.getElementById("checkshow").checked==true){
        	checkshow="none";
        }
        
        if(document.getElementById("abc_ngay").checked==true){
            txtloaitimkiem='ngay';
        }
        if(document.getElementById("abc_thang").checked==true){
            txtloaitimkiem='thang';
        }
        if(document.getElementById("abc_qui").checked==true){
            txtloaitimkiem='qui';
        }
        if(document.getElementById("abc_all").checked==true){
            txtloaitimkiem='all';
        }
	
        var body = document.getElementById('showview');
        body.setAttribute('style','opacity:.5; position:relative;cursor: wait;  ');
	
        var d=document.createElement('div');
        d.setAttribute('style','display: block;visibility: visible; position: absolute;  z-index: 999; top: 0px; left: 0px; width: 105%; height: 105%; text-align: center;  filter: alpha(opacity=5); opacity: 0.5; ');
	
        var image=document.createElement('img');
        image.setAttribute('src','images/loading1.gif');
        image.setAttribute('style','position:absolute; left:0px; top:0px; right:0; bottom:0; margin:auto');

	
        var typedate =$('input[name=ngaysearch]:checked').val();
	
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        /*var body = document.getElementById('content_code');
        body.setAttribute('style','opacity:.5; position:relative;cursor: wait;  ');
        var d=document.createElement('div');
        d.setAttribute('style','display: block;visibility: visible; position: absolute;  z-index: 999; top: 0px; left: 0px; width: 105%; height: 105%; text-align: center;  filter: alpha(opacity=5); opacity: 0.5; ');
        d.setAttribute('id','hanhanhan');
        var image=document.createElement('img');
        image.setAttribute('src','images/loading1.gif');
        image.setAttribute('style','position:absolute; left:0px; top:0px; right:0; bottom:0; margin:auto');
        d.appendChild(image);
    body.appendChild(d);*/
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("showview").innerHTML=xmlhttp.responseText;
                /*document.getElementById('content_code').setAttribute('style','opacity:1; position:relative;');
                                                                                        document.getElementById('hanhanhan').style.display='none';
                                                                                        document.getElementById('content_code').parentNode.removeChild('hanhanhan');*/
                document.getElementById('showview').setAttribute('style','opacity:1; position:relative;');
            }
        }
        if(txtloaitimkiem=="all"){
            var cusname=document.getElementById("inputString").value;
            var nam=document.getElementById("nam").value;
            var gt=document.getElementById("checknam").checked;
            if(gt==true){
                var gt1=document.getElementById("notthoigiangiaodich").checked;
                xmlhttp.open("GET","ajax/acc/or_search_invoice_tax_month.php?loaitimkiem=all&cusname="+encodeURIComponent(cusname)+"&typedate="+typedate+"&status="+status+"&not="+gt1+"&checkshow="+checkshow,true);
            }else{
                if(typedate=='ngayph')
                    var gt1=document.getElementById("notthoigiangiaodich").checked;
                xmlhttp.open("GET","ajax/acc/or_search_invoice_tax_month.php?loaitimkiem=all&cusname="+encodeURIComponent(cusname)+"&nam="+nam+"&typedate="+typedate+"&status="+status+"&not="+gt1+"&checkshow="+checkshow,true);
                if(typedate=='ngaygd'){
                    xmlhttp.open("GET","ajax/acc/or_search_invoice_tax_month.php?loaitimkiem=all&cusname="+encodeURIComponent(cusname)+"&nam="+nam+"&typedate="+typedate+"&status="+status+"&checkshow="+checkshow,true);
                }
			
			
            }
            xmlhttp.send();
        }else if(txtloaitimkiem=="ngay"){
            var cusname=document.getElementById("inputString").value;
            var df=document.getElementById("datefrom").value;
            var dt=document.getElementById("dateto").value;
            if(typedate=='ngayph')
                var gt1=document.getElementById("notthoigiangiaodich").checked;
            xmlhttp.open("GET","ajax/acc/or_search_invoice_tax.php?loaitimkiem=ngay&df="+df+"&dt="+dt+"&cusname="+encodeURIComponent(cusname)+"&typedate="+typedate+"&status="+status+"&not="+gt1+"&checkshow="+checkshow,true);
            if(typedate=='ngaygd'){
                xmlhttp.open("GET","ajax/acc/or_search_invoice_tax.php?loaitimkiem=ngay&df="+df+"&dt="+dt+"&cusname="+encodeURIComponent(cusname)+"&typedate="+typedate+"&status="+status+"&checkshow="+checkshow,true);
            }
            xmlhttp.send();
        }else if(txtloaitimkiem=="thang"){
            var cusname=document.getElementById("inputString").value;
            var eyear = document.getElementById("syear");
            var txtyear = eyear.options[eyear.selectedIndex].value;
            var emon = document.getElementById("smonths");
            var txtmon = emon.options[emon.selectedIndex].value;
            if(typedate=='ngayph')
                var gt1=document.getElementById("notthoigiangiaodich").checked;
            xmlhttp.open("GET","ajax/acc/or_search_invoice_tax_month.php?loaitimkiem=thang&nam="+txtyear+"&thang="+txtmon+"&cusname="+encodeURIComponent(cusname)+"&typedate="+typedate+"&status="+status+"&not="+gt1+"&checkshow="+checkshow,true);
            if(typedate=='ngaygd'){
                xmlhttp.open("GET","ajax/acc/or_search_invoice_tax_month.php?loaitimkiem=thang&nam="+txtyear+"&thang="+txtmon+"&cusname="+encodeURIComponent(cusname)+"&typedate="+typedate+"&status="+status+"&checkshow="+checkshow,true);
            }
            xmlhttp.send();
        }else if(txtloaitimkiem=="qui"){
            var cusname=document.getElementById("inputString").value;
            var eyear = document.getElementById("nam");
            var txtyear = eyear.options[eyear.selectedIndex].value;
            var emon = document.getElementById("qmonths");
            var txtmon = emon.options[emon.selectedIndex].value;
            if(typedate=='ngayph')
                var gt1=document.getElementById("notthoigiangiaodich").checked;
            xmlhttp.open("GET","ajax/acc/or_search_invoice_tax_qui.php?loaitimkiem=qui&nam="+txtyear+"&qui="+txtmon+"&cusname="+encodeURIComponent(cusname)+"&typedate="+typedate+"&status="+status+"&not="+gt1+"&checkshow="+checkshow,true);
            if(typedate=='ngaygd'){
                xmlhttp.open("GET","ajax/acc/or_search_invoice_tax_qui.php?loaitimkiem=qui&nam="+txtyear+"&qui="+txtmon+"&cusname="+encodeURIComponent(cusname)+"&typedate="+typedate+"&status="+status+"&checkshow="+checkshow,true);
            }
            xmlhttp.send();
		
        }
    }

    function changeyear(type){
        var eyear = document.getElementById("syear");
        var txtyear = eyear.options[eyear.selectedIndex].value;
        var emon = document.getElementById("smonths");
        var txtmon = emon.options[emon.selectedIndex].value;
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("showtime").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","ajax/acc/or_search_invoice_tax_time.php?type="+type+"&year="+txtyear+"&mon="+txtmon,true);
        xmlhttp.send();
    }
    function changeDistinction1(status){
        if(document.getElementById("abc_ngay").checked==true){
            type='ngay';
        }
        if(document.getElementById("abc_thang").checked==true){
            type='thang';
        }
        if(document.getElementById("abc_qui").checked==true){
            type='qui';
        }
        if(document.getElementById("abc_all").checked==true){
            type='all';
        }

        var typedate =$('input[name=ngaysearch]:checked').val();
        if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("idtab").innerHTML=xmlhttp.responseText;
                if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp=new XMLHttpRequest();
                }else{// code for IE6, IE5
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function(){
                    if (xmlhttp.readyState==4 && xmlhttp.status==200){
                        document.getElementById("showview").innerHTML=xmlhttp.responseText;
                        Load();
                    }
                }
                xmlhttp.open("GET","ajax/acc/resetShowView.php?status="+status+"&typedate="+typedate,true);
                xmlhttp.send();
            }
        }
        xmlhttp.open("GET","ajax/acc/changeDistinction.php?abc="+type+"&status="+status+"&typedate="+typedate,true);
        xmlhttp.send();
    }
    function changeDistinction(type,status){
        var typedate =$('input[name=ngaysearch]:checked').val();
        if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("idtab").innerHTML=xmlhttp.responseText;
                if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp=new XMLHttpRequest();
                }else{// code for IE6, IE5
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function(){
                    if (xmlhttp.readyState==4 && xmlhttp.status==200){
                        document.getElementById("showview").innerHTML=xmlhttp.responseText;
                        Load();
                    }
                }
                xmlhttp.open("GET","ajax/acc/resetShowView.php?status="+status+"&typedate="+typedate,true);
                xmlhttp.send();
            }
        }
        xmlhttp.open("GET","ajax/acc/changeDistinction.php?abc="+type+"&status="+status+"&typedate="+typedate,true);
        xmlhttp.send();
    }
    function changequi(type){
        var eyear = document.getElementById("nam");	
        var txtyear = eyear.options[eyear.selectedIndex].value;
        if(type!="tinhnam"){
            var emon = document.getElementById("qmonths");
            var txtmon = emon.options[emon.selectedIndex].value;
            if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            }else{// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange=function(){
                if (xmlhttp.readyState==4 && xmlhttp.status==200){
                    document.getElementById("showtime").innerHTML=xmlhttp.responseText;
                }
            }
		  
            xmlhttp.open("GET","ajax/acc/or_search_invoice_tax_time.php?type="+type+"&year="+txtyear+"&qui="+txtmon,true);
            xmlhttp.send();
        }else{
            var gt=document.getElementById("checknam").checked;
		
            if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            }else{// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange=function(){
                if (xmlhttp.readyState==4 && xmlhttp.status==200){
                    document.getElementById("showtime").innerHTML=xmlhttp.responseText;
                }
            }
            if(gt==false){
                xmlhttp.open("GET","ajax/acc/or_search_invoice_tax_time.php?type="+type+"&year="+txtyear,true);
            }else{
                xmlhttp.open("GET","ajax/acc/or_search_invoice_tax_time.php?type="+type,true);
            }
            xmlhttp.send();
        }
    }

    function changedatefrom(){
        //var t=document.getElementById("dateto").value;
        //document.getElementById("vttime").value=vl+" ~ "+t;
        //alert(document.getElementById("vttime").value);
    }

    function dokhung(){
        var gt=document.getElementById("checkkhung").checked;
        if(gt==true){
            document.getElementById("inputString").value="";
            document.getElementById("inputString").style.backgroundColor ="#e9edf4";
            $("#inputString").attr('readonly', 'readonly');
        }else{
            document.getElementById("inputString").value="";
            document.getElementById('inputString').style.backgroundColor ="#ffffff";
            $("#inputString").removeAttr('readonly');
            document.getElementById('inputString').focus();
        }
    }

    function donam(typedate){
        var gt=document.getElementById("checknam").checked;
        if(gt==true){
            //document.getElementById("nam").value="";
            document.getElementById("nam").style.backgroundColor ="#e9edf4";
            $("#nam").attr('disabled', 'disabled');
            if(typedate=='ngaygd'){
                $("#notthoigiangiaodich").removeAttr('disabled');
                document.getElementById('notthoigiangiaodich').focus();
            }
        }else{
            //document.getElementById("nam").value="";
            document.getElementById('nam').style.backgroundColor ="#ffffff";
            $("#nam").removeAttr('disabled');
            document.getElementById('nam').focus();
            if(typedate=='ngaygd'){
                document.getElementById("notthoigiangiaodich").style.backgroundColor ="#e9edf4";
                $("#notthoigiangiaodich").attr('disabled', 'disabled');
            }
        }

        changequi('tinhnam');
	
    }
    function setdata(id,lang,company){
        document.getElementById("orderid").value=id;
        document.getElementById("lang").value=lang;
        document.getElementById("company").value=company;
        popup_window_show('#sample', { pos : 'window-center', width : '600px', height:'800px'});
	
    }
    function sendmail(){
        /*var body = document.getElementById('showview');
        body.setAttribute('style','opacity:.5; position:relative;cursor: wait;  ');
	
        var d=document.createElement('div');
        d.setAttribute('style','display: block;visibility: visible; position: absolute;  z-index: 999; top: 0px; left: 0px; width: 105%; height: 105%; text-align: center;  filter: alpha(opacity=5); opacity: 0.5; ');
	
        var image=document.createElement('img');
        image.setAttribute('src','images/loading1.gif');
        image.setAttribute('style','position:absolute; left:0px; top:0px; right:0; bottom:0; margin:auto');
	
        d.appendChild(image);
	
    body.appendChild(d);	*/
    
        var id=document.getElementById("orderid").value;
        var lang=document.getElementById("lang").value;
        var company=document.getElementById("company").value;
        //alert(id+lang+company);
	
        if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                //document.getElementById('showview').setAttribute('style','opacity:1; position:relative;');
                alert("Send mail successful");
            }
        }
        xmlhttp.open("GET","ajax/acc/sendmail_order.php?id="+id+"&lang="+lang+"&company="+company,true);
	
        xmlhttp.send();
    }
    function onprinter(type,typedate,cusname,nam,mon,status){
        var str = "printer/or_printer_search_invoice_tax_thangqui.php?type="+type+"&typedate="+typedate+"&cusname="+cusname+"&year="+nam+"&mon="+mon+"&status="+status;
        var gt=document.getElementById("check_no").checked;
        if(gt==true)
            str=str+"&check_no=on";
        var gt=document.getElementById("check_ngaythangnam").checked;
        if(gt==true)
            str=str+"&check_ngaythangnam=on";
        var gt=document.getElementById("check_company_name").checked;
        if(gt==true)
            str=str+"&check_company_name=on";
        var gt=document.getElementById("check_product_item").checked;
        if(gt==true)
            str=str+"&check_product_item=on";
        var gt=document.getElementById("check_quantity").checked;
        if(gt==true)
            str=str+"&check_quantity=on";
        var gt=document.getElementById("check_Supply_price").checked;
        if(gt==true)
            str=str+"&check_Supply_price=on";
        var gt=document.getElementById("check_vat").checked;
        if(gt==true)
            str=str+"&check_vat=on";
        var gt=document.getElementById("check_amount").checked;
        if(gt==true)
            str=str+"&check_amount=on";
        var gt=document.getElementById("check_thoigiangiaodich").checked;
        if(gt==true)
            str=str+"&check_thoigiangiaodich=on";
        var gt=document.getElementById("check_memo").checked;
        if(gt==true)
            str=str+"&check_memo=on";
	
        window.open(str);
	
    }
    function onprinter1(type,typedate,cusname,df,dt,status){
        var str = "printer/or_printer_search_invoice_tax.php?type="+type+"&typedate="+typedate+"&cusname="+cusname+"&df="+df+"&dt="+dt+"&status="+status;
        var gt=document.getElementById("check_no").checked;
        if(gt==true)
            str=str+"&check_no=on";
        var gt=document.getElementById("check_ngaythangnam").checked;
        if(gt==true)
            str=str+"&check_ngaythangnam=on";
        var gt=document.getElementById("check_company_name").checked;
        if(gt==true)
            str=str+"&check_company_name=on";
        var gt=document.getElementById("check_product_item").checked;
        if(gt==true)
            str=str+"&check_product_item=on";
        var gt=document.getElementById("check_quantity").checked;
        if(gt==true)
            str=str+"&check_quantity=on";
        var gt=document.getElementById("check_Supply_price").checked;
        if(gt==true)
            str=str+"&check_Supply_price=on";
        var gt=document.getElementById("check_vat").checked;
        if(gt==true)
            str=str+"&check_vat=on";
        var gt=document.getElementById("check_amount").checked;
        if(gt==true)
            str=str+"&check_amount=on";
        var gt=document.getElementById("check_thoigiangiaodich").checked;
        if(gt==true)
            str=str+"&check_thoigiangiaodich=on";
        var gt=document.getElementById("check_memo").checked;
        if(gt==true)
            str=str+"&check_memo=on";
	
        window.open(str);
	
    }
</script>


<link rel="stylesheet" type="text/css" href="admin/css/jsDatePick_ltr.min.css" />

<script type="text/javascript" src="admin/css/jsDatePick.min.1.3.js"></script>

<script type="text/javascript">

    window.onload = function(){

        new JsDatePick({
            useMode:2,
            target:"datefrom",
            dateFormat:"%Y-%m-%d"
        });
        new JsDatePick({
            useMode:2,
            target:"dateto",
            dateFormat:"%Y-%m-%d"
        });

    };

</script>
<link	href="css/style.css" rel="stylesheet" type="text/css" />
<div  class="title" style="padding-top: 5px;font-weight: bold;"><?php echo $l_accountant; ?>&rarr; <?php if($status==0)echo $l_Invoice_thu; else echo $l_Invoice_chi; ?> &rarr; <?php if ($status == 0) echo $l_search_invoice_tax; else echo $l_SearchPurchase; ?></div>
<div class="content_code" id="content_code">

    <div class="approval-right">	
        <table cellpadding="0" cellspacing="0" width="100%" border="1" class="atable" >	
            <tr>
                <td class="ffirst" style="text-align:left;height:24px;width: 180px;"><span>*</span><?= $l_ngay ?></td>
                <td style="text-align:left;">
                    <label style="padding-left: 10px"><input type="radio" onclick="changeDistinction1(<?= $status ?>)"  id="ngayph" name="ngaysearch" value="ngayph" checked="checked"/><?= $l_ngayphathanh ?></label>
                    <label style="padding-left: 10px"><input type="radio" onclick="changeDistinction1(<?= $status ?>)"  id="ngaygd" name="ngaysearch" value="ngaygd"/><?= $l_ngaygiaodich ?></label>
                </td>
            </tr>
        </table>	


        <form action="" method="post" name="f_ac_elisoft_search_order_tax">
            <input type="hidden" name="content" value="ac_elisoft_search_order_tax_content" />
            <div style="width:100%" id="idtab">
                <table cellpadding="0" cellspacing="0" width="100%" border="1" class="atable" >		
                    <tr>
                        <td class="ffirst" style="text-align:left;height:24px;width:180px;"><span>*</span><?= $l_phanbiet ?></td>
                        <td style="text-align:left;min-width: 255px;">
                            <label style="padding-left: 10px"><input type="radio" onclick="changeDistinction('ngay',<?= $status ?>)" id="abc_ngay" name="abc_ngay" value="ngay"  <?php if ($_REQUEST["abc"] == "ngay")
    echo "checked"; ?> /><?= $l_theongay ?></label>
                            <label style="padding-left: 10px"><input type="radio" onclick="changeDistinction('thang',<?= $status ?>)" id="abc_thang" name="abc_thang" value="thang"  <?php if ($_REQUEST["abc"] == "thang")
    echo "checked"; ?> /><?= $l_theothang ?></label>
                            <label style="padding-left: 10px"><input type="radio" onclick="changeDistinction('qui',<?= $status ?>)" id="abc_qui" name="abc_qui" value="qui"  <?php if ($_REQUEST["abc"] == "qui")
    echo "checked"; ?> /><?= $l_theoqui ?></label>
                            <label style="padding-left: 10px"><input type="radio" onclick="changeDistinction('all',<?= $status ?>)" id="abc_all" name="abc_all" value="all"  <?php if ($_REQUEST["abc"] == "all")
    echo "checked"; ?> /><?= $l_all ?></label>
                        </td>
                        <?php
                        if ($_REQUEST["abc"] == "ngay") {
                            ?>
                                            <!-- <td class="ffirst" style="text-align:left"><span>*</span><?php echo $l_days; ?></td>
                                            <td  style="text-align:left;">
                                                    <input type="text" id="datefrom" name="datefrom" value="<?= $_REQUEST['datefrom'] ?>" class="ftext" readonly="readonly"/> ~ 
                                                    <input onchange="changedatefrom();" type="text" id="dateto" name="dateto" value="<?= $_REQUEST['dateto'] ?>" class="ftext" readonly="readonly"/>
    	                			</td>  -->
                            <td colspan="2"></td>
                            <?php
                        } else if ($_REQUEST["abc"] == "thang") {
                            ?>
                            <td class="ffirst" style="text-align:left"><span>*</span><?php echo $l_year . "-" . $l_month; ?></td>
                            <td  style="text-align:left;">
                                <div style="padding-left:9px;">
                                    <select onchange="changeyear('thang');" style="width:80px;height:22px;font-size:12px;" id="syear" name="syear">
                                        <?php for ($i = 2012; $i <= ($vyear+7); $i++) { ?>
                                            <option value="<?= $i ?>"  
                                            <?php
                                            if ($i == $_REQUEST['syear']) {
                                                ?>
                                                        selected="selected"
                                                        <?php
                                                    }
                                                    ?>
                                                    >
                                                        <?php echo $i ?>
                                            </option>
                                        <?php } ?>
                                    </select>  
                                    <select onchange="changeyear('thang');" style="width:50px;height:22px;font-size:12px;" id="smonths" name="smonths">
                                        <?php for ($i = 1; $i <= 12; $i++) { ?>
                                            <option value="<?= $i ?>"  
                                            <?php
                                            if ($i == $_REQUEST['smonths']) {
                                                ?>
                                                        selected="selected"
                                                        <?php
                                                    }
                                                    ?>
                                                    >
                                                        <?php echo $i ?>
                                            </option>
                                        <?php } ?>
                                    </select>  
                                </div>
                            </td>
                            <?php
                        } else if ($_REQUEST["abc"] == "qui") {
                            ?>
                            <td class="ffirst" style="text-align:left"><span>*</span><?php echo $l_year . "-" . $l_quy; ?></td>
                            <td  style="text-align:left;">
                                <div style="padding-left:9px;">
                                    <select onchange="changequi('tinhqui');" style="width:80px;height:22px;font-size:12px;" id="nam" name="nam">
                                        <?php for ($i = 2012; $i <= ($vyear+7); $i++) { ?>
                                            <option value="<?= $i ?>"  
                                            <?php
                                            if ($i == $_REQUEST['nam']) {
                                                ?>
                                                        selected="selected"
                                                        <?php
                                                    }
                                                    ?>
                                                    >
                                                        <?php echo $i ?>
                                            </option>
                                        <?php } ?>
                                    </select>  
                                    <select onchange="changequi('tinhqui');" style="width:50px;height:22px;font-size:12px;" id="qmonths" name="qmonths">
                                        <?php for ($i = 1; $i <= 4; $i++) { ?>
                                            <option value="<?= $i ?>"  
                                            <?php
                                            if ($i == $_REQUEST['qmonths']) {
                                                ?>
                                                        selected="selected"
                                                        <?php
                                                    }
                                                    ?>
                                                    >
                                                        <?php echo $i ?>
                                            </option>
                                        <?php } ?>
                                    </select>  
                                </div>
                            </td>
                            <?php
                        } else if ($_REQUEST["abc"] == "all") {
                            ?>
                            <td class="ffirst" style="text-align:left"><span>*</span><?php echo $l_year; ?></td>
                            <td  style="text-align:left;">
                                <div style="padding-left:9px;">
                                    <select onchange="changequi('tinhnam');" style="width:80px;height:22px;font-size:12px;" id="nam" name="nam">
                                        <?php for ($i = 2012; $i <= ($vyear+7); $i++) { ?>
                                            <option value="<?= $i ?>"  
                                            <?php
                                            if ($i == $_REQUEST['nam']) {
                                                ?>
                                                        selected="selected"
                                                        <?php
                                                    }
                                                    ?>
                                                    >
                                                        <?php echo $i ?>
                                            </option>
                                        <?php } ?>
                                    </select>  

                                    <label style="padding-left: 10px"><input type="checkbox" name="checknam" id="checknam" value="<?= $_REQUEST['checknam'] ?>" onclick="donam('<?= $typedate ?>')" />&nbsp;<?= $l_all ?></label>
                                    <?php if ($typedate == 'ngayph') { ?>
                                        <label style="padding-left: 10px"><input type="checkbox" id="notthoigiangiaodich"/><?= $thoigiangiaodich2 ?></label>
                                    <?php } ?>
                                </div>
                            </td>
                            <?php
                        }
                        ?>

                    </tr>
                    <tr>
                        <?php
                        if ($_REQUEST["abc"] == "ngay") {
                            ?>
                            <td class="ffirst" style="text-align:left"><span>*</span><?php echo $thoigianphgd; ?></td>
                            <td  style="text-align:left;">
                                <input type="text" id="datefrom" name="datefrom" value="<?= $_REQUEST['datefrom'] ?>" class="ftext" readonly="readonly" style="font-size:12px;font-weight:bold;text-align:center;"/> ~ 
                                <input type="text" id="dateto" name="dateto" value="<?= $_REQUEST['dateto'] ?>" class="ftext" readonly="readonly" style="font-size:12px;font-weight:bold;text-align:center;"/>
                            </td>
    <?php
} else {
    ?>
                            <td class="ffirst" style="text-align:left"><span></span><?= $thoigianphgd ?></td>
                            <td style="text-align:left">
                                <div id="showtime" style="padding-left:9px";>
                                     <input type="text" id="vttime" name="vttime" value="<?= $_REQUEST['vttime'] ?>" style="border:none;background:none;width:200px;font-size:12px;font-weight:bold;" readonly="readonly"/>
                                </div>
                            </td>
    <?php
}
?>
                        <td class="ffirst" style="text-align:left"><span></span><?= $l_company_name ?></td>
                        <td style="text-align:left">
                            <div style="position:relative;padding-left:9px;">
                                <div style="float:left;">
                                    <input  type="text" size="30" value="<?= $_REQUEST['cbcus'] ?>" name="cbcus" id="inputString"  style="height: 22px; width: 300px; border: 1px solid #c4c0c9;font-size: 12px;" autocomplete="off"; />
                                            <div class="suggestionsBox" id="suggestions" style="display:none;">
                                        <img src="images/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
                                        <div class="suggestionList" id="autoSuggestionsList">
                                            &nbsp;
                                        </div>
                                    </div> 						
                                </div>
                                <div style=" float:left; position:relative; margin-top: 4px; margin-left: -24px; z-index:999">
                                    <img alt="" src="images/arrow-down.png" id="menu_expand" >
                                    <div id="content_menu_expand" class="passul" style="display:none;">
                                        <ul>
<?php
$sql = "select ac_customer.CustomerName from ac_customer where ac_customer.Activest=1 ORDER BY ac_customer.CustomerName ASC";
$result = mysql_query($sql);
if ($result) {
    $i = 0;
    while ($row = mysql_fetch_array($result)) {
        ?>
                                                    <li onmouseover="this.style.cursor='pointer'"  onmouseout="this.style.cursor='default'" onclick="clickCustomer('<?= $row['CustomerName'] ?>')" 
                                                    <?php
                                                    if ($i % 2 != 0) {
                                                        ?>
                                                            class="bgkhac"
                                                        <?php
                                                    }
                                                    ?>
                                                        > <?php echo $row['CustomerName']; ?></li>
                                                        <?php
                                                        $i++;
                                                    }
                                                }
                                                ?>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                            <div style="padding:5px;">
                                <label style="padding-left: 10px"><input type="checkbox" name="checkkhung" id="checkkhung" value="<?= $_REQUEST['checkkhung'] ?>" onclick="dokhung()" />&nbsp;<?= $l_all ?></label>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>    
            <div style="text-align:center;">
            	<label><input type="checkbox" name="checkshow" id="checkshow" ><?=$l_checkshow?></label>
                <input onclick="viewclick(<?= $status ?>);" type="button" value="<?= $l_search ?>" class="btnupbg btnupload" style="background: #4f81bd;width: 80px" />
            </div>   
            <div style="clear:both"><br><br></div>  
            <div id="showview" style="width:100%">
                <div class="title2">
                        <!-- <span style="float:left"><?php echo $l_company_name ?> : ELisoft</span>
                        <span style="float:right">
<?php
if ($_REQUEST['cbcus'] != "") {
    ?>
                        <?php echo $l_tenkhachhanggiaodich; ?> : <?php echo $_REQUEST['cbcus']; ?>
                        <?php
                    }
                    ?>
			        </span> -->
                </div>
                <div style="clear:both"></div>
                <div style="position:relative">
                    <table cellpadding="0" cellspacing="1" width="100%" border="0" class="ftable">
                        <tr>
                            <th style=""><?= $l_no ?></th>
                            <th style="width: 10%;min-width: 100px"><?= $l_ngaythangnam ?></th>
                            <th style="width: 18%;min-width: 170px"><?= $l_company_name ?></th>
                            <th style="width: 35%;min-width: 220px"><?= $l_product_item ?></th>
                            <th style="display: none;"><?= $l_quantity ?></th>
                            <th style="width: 8%;min-width: 80px"><?= $l_Supply_price ?></th>
                            <th style="width: 8%;min-width: 80px"><?= $l_vat ?></th>
                            <th style="width: 8%;min-width: 80px"><?= $l_amount ?></th>
                            <th style="width: 10%;min-width: 100px"><?= $l_thoigiangiaodich ?></th>
                            <th style="width: 10%;min-width: 120px"><?= $l_memo ?></th>
                        </tr>

                        <tr class="coltr2" style="font-weight:bold;font-size:14px;">
                            <td colspan="4"  style="padding: 10px;">
<?php
if ($_SESSION['loaitimkiem'] == "ngay") {
    ?>
                                    <?php echo $l_ngay; ?> : <font color="red"><?php echo $thoigian; ?></font>  -  <?php echo $type; ?> : <font color="blue"><?php echo number_format($dem); ?></font>
                                    <?php
                                } else {
                                    ?>
                                    <?php echo $l_month; ?> : <font color="red"><?php echo $thoigian; ?></font>  -  <?php echo $type; ?> : <font color="blue"><?php echo number_format($dem); ?></font>											 
                                    <?php
                                }
                                ?>
                            </td>
                            <td style="display: none;"></td>
                            <td style="text-align:right;"><?php echo number_format($tonggiacungcap); ?></td>
                            <td style="text-align:right;"><?php echo number_format($tongthue); ?></td>
                            <td style="text-align:right;"><?php echo number_format($tongtien); ?></td>
                            <td></td>
                            <td></td>
                        </tr>
                        <tr style="font-weight:bold;font-size:15px;color:green;">
                            <td colspan="4" style="padding: 10px;"><?php echo $l_tongdon ?></td>
                            <td style="display: none;"></td>
                            <td style="text-align:right;"><?php echo number_format($stonggiacungcap); ?></td>
                            <td style="text-align:right;"><?php echo number_format($stongthue); ?></td>
                            <td style="text-align:right;"><?php echo number_format($stongtien); ?></td>
                            <td style="text-align:right;"></td>
                            <td style="text-align:right;"></td>
                            <td></td>
                        </tr>
                    </table>
                </div>
<?php
if (count($arr) > 0) {
    ?>
                    <div class="fbox2"><input type="button" value="Xuat file exe" class="btnupbg btnupload" style="background: #4f81bd;"/></div>
                    <div class="fbox2"><input type="button" value="<?= $l_print ?>" class="btnupbg btnupload" style="background: #4f81bd;"/></div>
                    <?php
                }
                ?>

            </div>
        </form>              	
    </div>

</div>